//
//  KHUICVCell_Home.m
//  EduCourse
//
//  Created by yanyan on 2017/8/9.
//  Copyright © 2017年 yanyan. All rights reserved.
//

#import "ECUICVCell_Home.h"
#import "ECFormatHelper.h"
#import "CourseModel.h"
#import <SDWebImage/UIButton+WebCache.h>
@interface ECUICVCell_Home()
@property(nonatomic,strong)UIImageView *imageView;
@property(nonatomic,strong)UILabel *titleLabel;//名字

@property(nonatomic,strong)UILabel *studyNumLabel;//多少人在学
@property(nonatomic,strong)UILabel *priceLabel;//价格

@end
@implementation ECUICVCell_Home
- (void)addSubviews
{
    [super addSubviews];
//    self.contentView.backgroundColor = [UIColor randomColor];
    self.imageView = [[UIImageView alloc]init];//[UIButton buttonWithType:UIButtonTypeCustom];
    [self.imageView setShowActivityIndicatorView:YES];
    [self.imageView setIndicatorStyle:UIActivityIndicatorViewStyleGray];
    self.imageView.userInteractionEnabled = NO;
    self.imageView.layer.cornerRadius = kCourseImageCornerRadius;
    self.imageView.layer.masksToBounds = YES;
//    self.imageView.contentMode = UIViewContentModeScaleAspectFit;//UIViewContentModeScaleAspectFit;//UIViewContentModeCenter;UIViewContentModeScaleToFill
    self.imageView.contentMode = UIViewContentModeScaleToFill;
    [self.contentView addSubview:self.imageView];
    _titleLabel = [[UILabel alloc]init];
    _titleLabel.font = [UIFont systemFontOfSize:13 * kPercentage];
    _titleLabel.textColor = [UIColor colorWithHexString:@"#333333"];
    _titleLabel.numberOfLines = 1;
    [self.contentView addSubview:_titleLabel];
    _studyNumLabel = [[UILabel alloc]init];
    _studyNumLabel.layer.masksToBounds = YES;
    _studyNumLabel.layer.cornerRadius = 5;
    _studyNumLabel.backgroundColor = [[UIColor colorWithHexString:@"#000000"]colorWithAlphaComponent:0.4];//[UIColor colorWithWhite:1 alpha:0.4];
    _studyNumLabel.font = [UIFont systemFontOfSize:9 * kPercentage];
    _studyNumLabel.textColor = [UIColor whiteColor];
    [self.imageView addSubview:_studyNumLabel];
    
    _priceLabel = [[UILabel alloc]init];
    _priceLabel.font = [UIFont systemFontOfSize:12 * kPercentage];//9
    _priceLabel.textColor = [UIColor colorWithHexString:@"#ef4023"];
    [self.contentView addSubview:_priceLabel];
    WeakSelf(weakSelf);
    [self.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.contentView).offset(17 * kPercentage);
        make.left.equalTo(weakSelf.contentView).offset(7 * kPercentage);
        make.right.equalTo(weakSelf.contentView).offset(-7*kPercentage);
        make.height.equalTo(weakSelf.imageView.mas_width ).multipliedBy(0.513);
//        make.centerY.equalTo(weakSelf.contentView);
    }];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.imageView.mas_bottom).offset(5);
        make.left.equalTo(weakSelf.imageView);
        make.right.equalTo(weakSelf.contentView);
    }];
    [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.titleLabel.mas_bottom).offset(5);
        make.left.equalTo(weakSelf.imageView);
        make.right.equalTo(weakSelf.contentView);
    }];
    [self.studyNumLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(weakSelf.imageView.mas_bottom).offset(-5);
        make.height.equalTo(@(20));
        make.right.equalTo(weakSelf.imageView).offset(-5);
    }];

}
- (void)setObject:(id)object
{
    [super setObject:object];
    CourseModel *mo = object;
    [self.imageView sd_setImageWithURL:[NSURL URLWithString:mo.pictureUrl] placeholderImage:nil];
    [self.titleLabel setText:mo.title];
    self.studyNumLabel.text = [NSString stringWithFormat:@"  %ld人在学  ",[mo.num integerValue]];
    self.priceLabel.attributedText = [ECFormatHelper attributedStringForPromotionPrice:[object valueForKey:@"price"] decimal:2 smallFontSize:9 * kPercentage];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
